package com.neusoft.zqygbc.neusoft_wenda.fragment;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.neusoft.zqygbc.neusoft_wenda.R;
import com.neusoft.zqygbc.neusoft_wenda.adapter.CreateQuestionAdapter;
import com.neusoft.zqygbc.neusoft_wenda.base.RetrofitCallback;
import com.neusoft.zqygbc.neusoft_wenda.javeBean.MyQuestionList;
import com.neusoft.zqygbc.neusoft_wenda.javeBean.QuestionEntity;
import com.neusoft.zqygbc.neusoft_wenda.model.QusetionModel;

import java.util.List;

import retrofit2.Call;

import static android.content.Context.MODE_PRIVATE;


/**
 * Created by dell on 2016/6/20.
 */
public class HisQuizFragment extends Fragment {

    private XRecyclerView myquestion_xrv;
    private QusetionModel qusetionModel;
    private Call call;
    private RetrofitCallback<MyQuestionList> myQuestionListRetrofitCallback;

    private Intent intent;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_quiz, null);

        initView(view);
        initData();
        return view;
    }

    private void initView(View view) {
        intent = getActivity().getIntent();
        myquestion_xrv = (XRecyclerView) view.findViewById(R.id.myquestion_xrv);
        myquestion_xrv.setLayoutManager(new LinearLayoutManager(getActivity()));
    }

    private void initData() {
        qusetionModel = new QusetionModel();
        call = qusetionModel.myquestionlist(intent.getStringExtra("user_id"));
        myQuestionListRetrofitCallback = new RetrofitCallback<MyQuestionList>() {
            @Override
            public void onResponse(MyQuestionList myQuestionList) {
                List<QuestionEntity> questionEntity = myQuestionList.getQuestion();
                if (questionEntity != null) {
                    myquestion_xrv.setAdapter(new CreateQuestionAdapter(getActivity(), questionEntity, R.layout.cardview_myquestion));
                }

            }
        };
        qusetionModel.bindCallback(call, myQuestionListRetrofitCallback);

    }
}
